package org.example.lc;

import java.util.Arrays;

/**
 * 最长连续序列
 * @author carol
 */
public class LeetCode128 {
    public static int longestConsecutive(int[] nums) {
        Arrays.sort(nums);
        int maxLength = 1;
        int currentLength = 1;
        for(int i = 0 ; i< nums.length-1;i++){
            if(nums[i+1]-nums[i]==1){
                currentLength++;
            } else if (nums[i+1]-nums[i]==0) {

            } else{
                currentLength = 1;
            }
            if(currentLength>maxLength){
                maxLength = currentLength;
            }
        }
        return maxLength;
    }

    public static void main(String[] args) {
        int[] nums = {1,2,0,1};
        longestConsecutive(nums);
        System.out.println(longestConsecutive(nums));
    }
}
